layui.use(['jquery', 'layarea', 'form', 'layer', 'laydate'], function () {
    var $ = layui.jquery;
    var form = layui.form;
    var layer = layui.layer;
    var laydate = layui.laydate;
    var layarea = layui.layarea;

    layarea.render({
        elem: "#area-picker",
        change:function (res){
            console.log(res)
        }
    })
    // 加载时间
    laydate.render({
        elem: '#deliveryDate'
    })
    var detailAddress =$('input[name="detailAddress"]').val();
    $('#addBasic').on('click', function () {
        var province = $('.province-selector').parent().find('.layui-input').val()
        var city = $('.city-selector').parent().find('.layui-input').val();
        var county = $('.county-selector').parent().find('.layui-input').val();
        var address = province + city + county + detailAddress;
        $("#customerAddress").val(address)
    })


    form.on('submit(addBasic)', function (data) {
        var index = layer.msg("数据提交中，请稍后", {
            icon: 16,
            time: false,
            shade: 0.8
        })


        var formData = data.field;
        var url = ctx + "/sale/addBasic";

        $.post(url, formData, function (result) {
            console.log(result)
            if (result.code == 200) {
                layer.msg("添加成功", {icon: 6});
                layer.close(index);
                layer.closeAll("iframe")
                parent.location.reload();
            } else {
                top.layer.msg(result.msg, {icon: 5})
            }
        })
        return false;

    })


})